/**
 * https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/
 * 两数之和
 * @param numbers 
 * @param target 
 */
const twoSum = (numbers: number[], target: number): number[] => {
    // 存储剩余的值 value是值对应的索引
    const map: Record<number, number> = {};

    // 数组长度
    const len = numbers.length;

    // 存入答案
    let ans: number[] = [-1, -1]

    for (let i = 0; i < len; i++) {
        let curr = numbers[i];
        if (map[curr] == undefined) {
            // 还没存在
            map[target - curr] = i + 1;
        } else {
            // 已经存在了, 找到了
            ans = [map[curr], i + 1]
            break;
        }
    }

    return ans
};